// 克隆函数，在getters里面进行对象数组的克隆缓存
export function cloneObj(obj) {
  var copy
  switch (typeof obj) {
    case 'undefined':
      break
    case 'number':
      copy = obj - 0
      break
    case 'string':
      copy = obj + ''
      break
    case 'boolean':
      copy = obj
      break
    // object分为两种情况 对象（Object）和数组（Array）
    case 'object':
      if (obj === null) {
        copy = null
      } else {
        if (Object.prototype.toString.call(obj).slice(8, -1) === 'Array') {
          copy = []
          for (var i = 0; i < obj.length; i++) {
            copy.push(cloneObj(obj[i]))
          }
        } else {
          copy = {}
          for (var j in obj) {
            copy[j] = cloneObj(obj[j])
          }
        }
      }
      break
    default:
      copy = obj
      break
  }
  return copy
}
